Back to course home
0% completed
Vote For New Content
Oracle Hard
Integer to English Words (hard)
Solution: Integer to English Words
Trapping Rain Water (hard)
Solution: Trapping Rain Water
First Missing Positive (hard)
Solution: First Missing Positive
Merge K Sorted Lists (hard)
Solution: Merge K Sorted Lists
Max Points on a Line (hard)
Solution: Max Points on a Line
Sudoku Solver (hard)
Solution: Sudoku Solver
Longest Valid Parentheses (hard)
Solution: Longest Valid Parentheses
Remove Nth Node From End of List (Medium)
Solution: Remove Nth Node From End of List
Median of Two Sorted Arrays (hard)
Solution: Median of Two Sorted Arrays
Constrained Subsequence Sum (hard)
Solution: Constrained Subsequence Sum
Simplify Path (medium)
Problem Statement
Given an absolute file path in a Unix-style file system, simplify it by converting ".." to the previous directory and removing any "." or multiple slashes. The resulting string should represent the shortest absolute path.
Examples
Example 1
- Input: path = "/a//b////c/d//././/.."
- Expected Output: "/a/b/c"
- Explanation:
- Convert multiple slashes (
//) into single slashes (/). "."refers to the current directory and is ignored.".."moves up one directory, so"d"is removed.- The simplified path is
"/a/b/c".
- Convert multiple slashes (
Example 2
- Input: path = "/../"
- Expected Output: "/"
- Explanation:
".."moves up one directory, but we are already at the root ("/"), so nothing happens.- The final simplified path remains
"/".
Example 3
- Input: path = "/home//foo/"
- Expected Output: "/home/foo"
- Explanation:
- Convert multiple slashes (
//) into single slashes (/). - The final simplified path is
"/home/foo".
- Convert multiple slashes (
Constraints:
1 <= path.length <= 3000- path consists of English letters, digits, period '.', slash '/' or '_'.
- path is a valid absolute Unix path.
Try it yourself
Try solving this question here:
Java
. . . .
Solution: 3Sum
Solution: Simplify Path
Mark as Completed
On this page
Problem Statement
Examples
Try it yourself